﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Filmy.Kontroler;

namespace Filmy
{
    public partial class Fobrazek : Form
    {
        public Fobrazek(Image im, int wysokosc, int szerokosc)
        {
            InitializeComponent();
            fw = new Filmweb();
            img = im;
            wys = wysokosc;
            szer = szerokosc;
        }
        Image img = null;
        int wys, szer;
        Filmweb fw;
        public Fobrazek(string tytul)
        {
            InitializeComponent();
            fw = new Filmweb();
            bgwObrazek.RunWorkerAsync(tytul);
        }

        private void bgwObrazek_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string adres = fw.dajDuzyObrazek(e.Argument.ToString());
                img = Image.FromFile(adres);
            }
            catch
            {
                img = Filmy.Properties.Resources.BrakObrazka;
            }
        }

        private void bgwObrazek_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            pictureBox1.Image = img;
            this.Height = img.Size.Height;
            this.Width = img.Size.Width;
        }

        private void Fobrazek_MouseClick(object sender, MouseEventArgs e)
        {
            bgwObrazek.CancelAsync();
            bgwObrazek.Dispose();
            pictureBox1.Image = null;
            this.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
